package com.istart.curator;

import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.curator.retry.RetryNTimes;
import org.junit.Test;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args ) throws Exception
    {
    	CuratorFramework client = CuratorFrameworkFactory.builder()
    			.connectString("127.0.0.1:2181")
    			.namespace("/brokers")
    			.retryPolicy(new RetryNTimes(Integer.MAX_VALUE, 1000))
    			.connectionTimeoutMs(5000)
    			.build(); 
    	// 启动 上面的namespace会作为一个最根的节点在使用时自动创建  
    	//Start the client. Most mutator methods will not work until the client is started
        client.start();  
     // 创建一个节点  
//        client.create().forPath("/head", new byte[0]);  
    }
    private final static String connectString = "127.0.0.1:2181";
    @Test public void test(){
    	RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
    	CuratorFramework client = CuratorFrameworkFactory.newClient(connectString, retryPolicy);
    	client.start();
    }
}
